home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_08_07 / 8n07122b < prev    next >
Text File  |  1990-06-17  |  2KB  |  56 lines

  1. /* Listing 8*/
  2. /***********************************************************
  3.   Testlist.c - Program to test the list object using a phone
  4.   list as an example.
  5. ***********************************************************/
  6. #include "phlist2.h"
  7.  
  8. static PHONE_ENTRY test_data[] = {
  9. {"Able","Ben","456-7890"},{"Smith","John","456-0987"},
  10. {"Kirk","Jim","622-1701"},{"Picard","Jon L.","622-1701"},
  11. {"Jones","Cyrano","874-2253"}
  12. };
  13.  
  14. static PHONE_ENTRY jane = {"Smith","Jane","123/456-0987"};
  15.  
  16. main()
  17. {
  18.     PHONE_LIST *pe;
  19.     int x;
  20.  
  21.     pe = new_phone_list();
  22.     for (x = 0; x < 5; ++x)
  23.         pe->add_member(pe,&test_data[x]);
  24.     printf("\nTesting Phone List:\n");
  25.     pe->top(pe);
  26.  
  27.     while( ! pe->at_end(pe) ) {
  28.        pe->display(pe); pe->next(pe);
  29.     }
  30.     printf("\n Finding - Kirk \n");
  31.     pe->top(pe);
  32.     if (pe->find(pe,"Kirk") == TRUE)
  33.         pe->display(pe);
  34.     printf("\n Trying to find McCoy \n");
  35.     if (pe->find(pe,"McCoy") == FALSE)
  36.         printf("\nMcCoy not found\n");
  37.     printf("Current Member is :\n");
  38.     pe->display(pe);
  39.     printf("Replace John Smith with Jane\n");
  40.     pe->top(pe);
  41.     if (pe->find(pe,"Smith") == TRUE) {
  42.     pe->replace_member(pe,&jane);
  43.     }
  44.     else {
  45.         printf("Not Found (Strike a Key)\n"); getch();
  46.     }
  47.     printf("\nRedisplaying phone list:\n");
  48.     pe->top(pe);
  49.     while( ! pe->at_end(pe) ) {
  50.        pe->display(pe);  pe->next(pe);
  51.     }
  52.     pe->end(pe);
  53.     printf("Total members = %ld\n",pe->total_members(pe));
  54.     printf("Current member = %ld\n",pe->tell(pe));
  55. }
  56.